package com.xvyy.tingshu.search.api;

import com.xvyy.tingshu.common.result.Result;
import com.xvyy.tingshu.query.search.AlbumIndexQuery;
import com.xvyy.tingshu.search.service.SearchService;
import com.xvyy.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    //http://192.168.217.1:8500/api/search/albumInfo/channel/1
    @GetMapping("channel/{c1Id}")
    @Operation(summary = "首页数据的展示")
    public Result channel(@PathVariable(value = "c1Id") Long c1Id) {
        List<Map<String, Object>> map = searchService.channel(c1Id);
        return Result.ok(map);
    }

    //http://192.168.217.1:8500/api/search/albumInfo
    @PostMapping
    @Operation(summary = "搜索专辑")
    public Result searchAlbum(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.searchAlbum(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    //http://192.168.217.1:8500/api/search/albumInfo/completeSuggest/{content}
    @GetMapping("completeSuggest/{content}")
    @Operation(summary = "关键字自动补全")
    public Result autoCompleteSuggest(@PathVariable(value = "content") String content) {
        Set<String> setResult = searchService.autoCompleteSuggest(content);
        return Result.ok(setResult);
    }

}

